<#assign menu="merchant_add">
<#include "/system/head.ftl">
<link rel="stylesheet" type="text/css" href="${basePath}/assets/global/plugins/clockface/css/clockface.css"/>
<link rel="stylesheet" type="text/css"
      href="${basePath}/assets/global/plugins/bootstrap-datepicker/css/datepicker3.css"/>
<link rel="stylesheet" type="text/css"
      href="${basePath}/assets/global/plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css"/>
<link rel="stylesheet" type="text/css"
      href="${basePath}/assets/global/plugins/bootstrap-colorpicker/css/colorpicker.css"/>
<link rel="stylesheet" type="text/css"
      href="${basePath}/assets/global/plugins/bootstrap-daterangepicker/daterangepicker-bs3.css"/>
<link rel="stylesheet" type="text/css"
      href="${basePath}/assets/global/plugins/bootstrap-datetimepicker/css/datetimepicker.css"/>

<link rel="stylesheet" type="text/css"
      href="${basePath}/assets/global/plugins/bootstrap-select/bootstrap-select.min.css"/>
<link rel="stylesheet" type="text/css" href="${basePath}/assets/global/plugins/select2/select2.css"/>
<link rel="stylesheet" type="text/css"
      href="${basePath}/assets/global/plugins/jquery-multi-select/css/multi-select.css"/>

<link href="${basePath}/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/assets/global/css/plugins.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/assets/admin/layout/css/layout.css" rel="stylesheet" type="text/css"/>
<link id="style_color" href="${basePath}/assets/admin/layout/css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/assets/admin/layout/css/custom.css" rel="stylesheet" type="text/css"/>



<script language="javascript" src="http://webapi.amap.com/maps?v=1.3&key=0124fded525ed5c45b8bc81d43a0db5a"></script>

<body>
<section id="main-content">
    <section class="wrapper">
        <div class="tab-content">

            <div class="tab-pane active" id="tab_2">
                <div class="portlet box green">
                    <div class="portlet-title">
                        <div class="caption">
                            <i class="fa fa-gift"></i>编辑职位
                        </div>
                    </div>
                    <div class="portlet-body form">
                        <!-- BEGIN FORM-->
                        <form onSubmit="return false" id="addForm" method="post" action="${basePath}/admin/job/edit.json"
                              class="form-horizontal">
                            <input type="hidden" id="jobId" name="jobId" value="${job.id}">
                            <input type="hidden" id="merchantId" name="merchantId" value="${job.merchantId}">


                            <div class="form-body">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">职位名称
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <input name="name" type="text" value="${job.name}" class="form-control" >
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">职位类型
                                                <span class="required" aria-required="true">* </span>
                                            </label>
                                            <div class="col-md-9">
                                                <select name="jobType" id="jobType-select" class="form-control" value="${job.jobType}">
                                                <#list categoryList as e>
                                                    <option value=${e.id}>${e.name}</option>
                                                </#list>
                                                </select>


                                            </div>
                                        </div>
                                    </div>

                                </div>


                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">发布商户</label>

                                            <div class="col-md-9">
                                                <input type="text"  id="merchant"
                                                       class="form-control select2 select2-offscreen" tabindex="-1"
                                                       title="" >
                                            </div>

                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">工作时间
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <input class="form-control" value="${job.jobTime}" type="text"
                                                       name="jobTime">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">工作地点
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <input class="form-control" name="jobAddress" value="${job.jobAddress}" type="text" >
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label col-md-3">招聘人数
                                            <span class="required" aria-required="true">* </span>
                                        </label>

                                        <div class="col-md-9">
                                            <input class="form-control" value="${job.recruitNum}" id="recruitNum" type="text"
                                                   name="recruitNum">
                                            <span class="help-block">(输入数字)</span>
                                        </div>
                                    </div>
                                </div>
                            </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">候选人数
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <input class="form-control" value="${job.candidateNum}" id="candidateNum" type="text"
                                                       name="candidateNum">
                                                <span class="help-block">(输入数字)</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">佣金
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <input class="form-control" name="amount" value="${job.amount}" id="amount" type="text" >

                                                <span class="help-block">(输入数字)</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            <#--<div class="row">-->
                            <#--<div class="col-md-6">-->
                            <#--<div class="form-group">-->
                            <#--<label class="control-label col-md-3">付款方式-->
                            <#--<span class="required" aria-required="true">* </span>-->
                            <#--</label>-->

                            <#--<div class="col-md-3">-->
                            <#--<label>-->
                            <#--<div class="checkbox-inline"><span class=""><input type="radio"  name="salaryType" ></span></div> cash </label>-->
                            <#--<label>-->
                            <#--<div class="checkbox-inline"><span class=""><input type="radio"  name="salaryType" ></span></div> payTreasure </label>-->
                            <#--</div>-->
                            <#--</div>-->
                            <#--</div>-->
                            <#--</div>-->
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">结薪方式
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <select name="payCycle" id="payCycle-select" class="form-control" value="${job.payCycle}">
                                                    <option value="hour">时</option>
                                                    <option value="day">天</option>
                                                    <option value="week">周</option>
                                                    <option value="month">月</option>
                                                </select>


                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">开始时间
                                                <span class="required" aria-required="true">* </span></label>

                                            <div class="col-md-4">
                                                <div class="input-group input-large date-picker input-daterange"
                                                     data-date="" data-date-format="yyyy-mm-dd">
                                                    <input type="text" value="${job.startTime?string('yyyy-MM-dd')}" class="form-control" name="startTime">
												<span class="input-group-addon">
												至 </span>
                                                    <input type="text" value="${job.endTime?string('yyyy-MM-dd')}" class="form-control" name="endTime">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">审核状态
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <select name="status" id="status-select" class="form-control" >
                                                    <option value="audit" selected>已审核</option>
                                                    <option value="noAudit">未审核</option>
                                                </select>


                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <#--<div class="row">-->
                            <#--<div class="col-md-6">-->
                            <#--<div class="form-group">-->
                            <#--<label class="control-label col-md-3">图片展示</label>-->

                            <#--<div class="col-md-9">-->
                            <#--<input name="imgUrl" type="text" class="form-control">-->

                            <#--</div>-->
                            <#--</div>-->
                            <#--</div>-->
                            <#--</div>-->
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">职位简介
                                                <span class="required" aria-required="true">* </span>
                                            </label>

                                            <div class="col-md-9">
                                                <textarea name="description" rows="10" cols="118">${job.description}</textarea>
                                            </div>



                                        </div>
                                    </div>

                                </div>
                            </div>


                            <div class="row">
                                <div class="col-md-6">
                                    <div class="col-md-offset-3 col-md-9">
                                        <button type="submit" class="btn green">提交修改</button>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
</section>
</body>


<script type="text/javascript">
    var kindId = "${kindId}";
    var kind = "article";
    $.extend({
        getAttachment: function () {
            $.getJSON("${basePath}/admin/attachment/list.json?kindId=" + kindId + "&v=" + Math.random(), function (data) {
                $('#attachment').html("");
                $.addAttachment(data.attachmentList);
            });
        },
        addAttachment: function (list) {
            var html = '<table class="table"><thead><tr><th>文件名</th><th>链接</th><th>大小</th><th>操作</th></tr></thead><tbody>';
            var urlList;
            for (i = 0; i < list.length; i++) {
                var attachment = list[i];
                html += '<tr>';
                if (attachment.type == "photo") {
                    html += '';
                } else {
                    html += '<td>' + attachment.name + '</td>';
                }
                html += '<td>' + attachment.link + '</td><td>' + attachment.size + '</td><td>';
                html += '<a href="javascript:void(0);" title="删除" name="' + attachment.name + '" class="btn btn-danger btn-xs js_delete" attachmentId="' + attachment.attachmentId + '">删除</a> ';
                html += '</td></tr>';
                urlList += attachment.link + ",";
            }
            $("#credentials").val(urlList);
            html += '</tbody></table>';
            $('#attachment').prepend(html);
            $('#attachment .js_delete').click(function () {
                var file = $(this);
                bootbox.confirm("是否要删除【" + $(this).attr("name") + "】文件？", function (result) {
                    if (result) {
                        $.post("${basePath}/admin/attachment/delete.json", {'attachmentId': file.attr("attachmentId")}, function (data) {
                            if (data.result) {
                                $.getAttachment();
                            }
                        }, "json");
                    }
                });
            });
            $('#attachment .js_status').click(function () {
                $.post("${basePath}/admin/attachment/update_status.json", {
                    'attachmentId': $(this).attr("attachmentId"),
                    'status': $(this).attr("status")
                }, function (data) {
                    if (data.result) {
                        $.getAttachment();
                    }
                }, "json");
            });
            $('#attachment .js_link').click(function () {
                var attachmentId = $(this).attr("attachmentId");
                bootbox.prompt("为此附件增加链接", function (result) {
                    if (result != "") {
                        $.post("${basePath}/admin/attachment/update_link.json", {
                            'attachmentId': attachmentId,
                            'link': result
                        }, function (data) {
                            if (data.result) {
                                $.getAttachment();
                            }
                        }, "json");
                    }
                });
            });
        }
    });
    $(function () {
        $('#fileForm').ajaxForm({

            success: function (data) {
                if (data.result) {
                    bootbox.alert("保存成功");
                } else {
                    bootbox.alert(data.msg);
                }
            },
            error: function (data) {

            }
        });
        $('#file_upload').uploadify({
            'buttonText': '请选择文件',
            'swf': '${basePath}/system/assets/uploadify/uploadify.swf',
            'uploader': '${basePath}/admin/attachment/upload.json;jsessionid=${JSESSIONID}',
            'formData': {'kindId': kindId, 'kind': kind},
            'fileObjName': 'file',
            'fileTypeExts': '*.*',
            'method': 'post',
            'onUploadSuccess': function (file, data, response) {
                $.getAttachment();
            }
        });
        $.getAttachment();
    });


</script>

<script language="javascript">
    var mapObj;
    var marker = new Array();
    var windowsArr = new Array();

    mapObj = new AMap.Map("iCenter");

    function geocoder() {

        var MGeocoder;
        //加载地理编码插件
        mapObj.plugin(["AMap.Geocoder"], function () {
            MGeocoder = new AMap.Geocoder({
                radius: 5000 //范围，默认：500
            });
            //返回地理编码结果
            AMap.event.addListener(MGeocoder, "complete", geocoder_CallBack);
            //地理编码
            MGeocoder.getLocation($("#city_2 .prov").val() + $("#city_2 .city").val() + $("#city_2 .dist").val() + $("#address").val());
        });
    }
    //地理编码返回结果展示
    function geocoder_CallBack(data) {
        var resultStr = "";
        //地理编码结果数组
        var geocode = new Array();
        geocode = data.geocodes;
        console.log(data);
        $("#latitude").val(geocode[0].location.getLat());
        $("#longitude").val(geocode[0].location.getLng());
    }
</script>


<#include "/system/foot.ftl">
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/bootstrap-timepicker/js/bootstrap-timepicker.min.js"></script>
<script type="text/javascript" src="${basePath}/assets/global/plugins/clockface/js/clockface.js"></script>
<script type="text/javascript" src="${basePath}/assets/global/plugins/bootstrap-daterangepicker/moment.min.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/jquery-inputmask/jquery.inputmask.bundle.js"></script>

<script src="${basePath}/assets/admin/pages/scripts/components-pickers.js"></script>

<script type="text/javascript"
        src="${basePath}/assets/global/plugins/bootstrap-select/bootstrap-select.min.js"></script>
<script type="text/javascript" src="${basePath}/assets/global/plugins/select2/select2.js"></script>
<script type="text/javascript" src="${basePath}/assets/global/plugins/select2/select2_locale_zh-CN.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/jquery-multi-select/js/jquery.multi-select.js"></script>
<script src="${basePath}/assets/admin/pages/scripts/components-dropdowns.js"></script>
<script src="${basePath}/assets/admin/pages/scripts/components-form-tools.js"></script>
<script type="text/javascript"
        src="${basePath}/assets/global/plugins/jquery-inputmask/jquery.inputmask.bundle.min.js"></script>

<script>

    $('#addForm').validate({

        submitHandler: function (form) {

            $('#addForm').ajaxSubmit(function (data) {

                if (data.result) {

                    location.href = "/admin/job/page.htm";
                } else {
                    $('.alert-danger span', $('#addForm')).html(data.msg);
                    $('.alert-danger', $('#addForm')).show();

                }
            });
        }
    });
    Metronic.init(); // init metronic core components
    //    ComponentsDropdowns.init();

    $('.date-picker').datepicker({
        rtl: Metronic.isRTL(),
        autoclose: true,
        language:"zh-CN"

    });
    $("#recruitNum").inputmask({
        "mask": "9",
        "repeat": 10,
        "greedy": false
    });

    $("#amount").inputmask({
        "mask": "9",
        "repeat": 10,
        "greedy": false
    });

    $("#candidateNum").inputmask({
        "mask": "9",
        "repeat": 10,
        "greedy": false
    });


    $("#merchant").select2({
        placeholder: "${job.merchantName}",
        minimumInputLength: 1,
        id: function(obj) {
            return obj.id;
        },
        ajax: {
            url: "/admin/merchant/search.json",

            quietMillis: 1000,
            data: function (term, page) {
                return {
                    merchantName: term

                };
            },
            cache: true,
            results: function (data, page) { // parse the results into the format expected by Select2.
//                console.log(data);
                // since we are using custom formatting functions we do not need to alter remote JSON data
                return {
                    results: jQuery.parseJSON(data.t)
                };
            }
        },



        formatResult: movieFormatResult,
        formatSelection: function(merchant) {
            selectedMerchant=merchant;
            return merchant.merchantName;
        },
        dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
        escapeMarkup: function (m) {
            return m;
        } // we do not want to escape markup since we are displaying html in results
    });

    var selectedMerchant;
    function movieFormatResult(merchant) {
        var markup = "<table class='movie-result'   ><tr>";
        markup += "<td valign='top' id='merchantId_" + merchant.id + "'>" + merchant.merchantName + "</td>";
        markup += "<td style='font-size: 14px;margin-left: 10px;'>(" +merchant.province+"-"+merchant.city+"-"+merchant.area+"-"+ merchant.address + ")</td>";
        markup += "</td></tr></table>"
        return markup;
    }
    $("#jobType-select").val("${job.jobType}");
    $("#payCycle-select").val("${job.payCycle}");
    $("#status-select").val("${job.status}")

</script>

